// 用于为游客和普通用户生成商品列表
// import {classfier_filter, all_filter, init_classfier_list} from './shop-classifier-list-for-user';

let base_items;

$(function () {
    init_shop_list(null, null);
})

function init_shop_list(color_filter, size_filter) {
    // console.log('开始加载商品列表')
    $.ajax({
        url: `/products-list-onshop?color-filter=${color_filter == null ? '_all' : color_filter}&size-filter=${size_filter == null ? '_all' : size_filter}`,
        type: 'GET',
        dataType: 'JSON',
        success: function (data) {
            if (data.status) {
                $('#shop-body').empty();
                var result_list = new Array(data.result);
                result_list.forEach((value, _idx, _arr) => {
                    value.forEach((sub_value, _sub_idx, _sub_arr) => {
                        $s_body = `
                            <div class="col-lg-4 col-md-6 col-sm-12 pb-1 shop-clicker" s-size="${sub_value['size']}" s-color="${sub_value['color']}">
                                <div class="card product-item border-0 mb-4">
                                    <div class="card-header product-img position-relative overflow-hidden bg-transparent border p-0">
                                        <img class="img-fluid w-100" src="${sub_value['image']}" alt="">
                                    </div>
                                    <div class="card-body border-left border-right text-center p-0 pt-4 pb-3">
                                        <h6 class="text-truncate mb-3">${sub_value['name']}</h6>
                                    </div>
                                    <div class="card-footer d-flex justify-content-between bg-light border">
                                    </div>
                                </div>
                            </div>
                        `;
                        $('#shop-body').append($s_body);
                    });
                });
                base_items = $.extend(true, [], $('#shop-body'));
                shop_click();
                // init_classfier_list();
                // classfier_filter();
            } else {
                alert('获取商品数据失败，请检查后台重试');
            }
        }
    });
}

function shop_click() {
    $('.shop-clicker').click(function () {
        alert('请先登录!');
        window.location.href = '/page/login.html';
    });
}